import axios from 'axios';

var qs = require('qs');

let basePath = '/api/v1.0/admin/';
let basePath2 = '/api/v2.0/admin/';

/**
 * 路径  start
 * ----------------------------------------------------------------------------------------------------------------------
 */
const DICTENTITY = basePath + 'fdict_entitys/fdict_entitys';

const MARKCARGOS = basePath2 + 'mark_cargoss';

const MARK_CARGO_NO_PAGE = basePath2 + 'mark_cargo_no_page/';

const MARKCARGOS_DEL = basePath2 + 'mark_cargos/';

const MARKCARGO = basePath2 + 'mark_cargo';

const ADDRESS_DICTS = basePath + `address_dicts`;

const ORGANIZATION_LIST = basePath + 'organizations/list';

const MARK_CARGO_ADDRESSS = basePath2 + 'mark_cargo_addresss';

const MARK_CARGO_ADDRESS = basePath2 + 'mark_cargo_address';

const MARK_CARGO_ADDRESS_BY_MARK_CARGO_ID = basePath2 + 'mark_cargo_address_by_mark_cargo/';

const MARK_CARGO_ADDRESS_DEL_BY_USER_ID_MARK_CARGO_ID = basePath2 + 'mark_cargo_address_by_user_id_mark_cargo/';

const MARK_CARGO_ADDRESS__BY_USER_ID_MARK_CARGO_ID = basePath2 + 'mark_cargo_address_by_user_id_mark_cargo';

const MARKCARGO_BY_ID = basePath2 + 'mark_cargo' + '/';

const MARK_CARGO_ADDRESS_BY_ID_IS_NULL = basePath2 + 'mark_cargo_address_id_is_null';

/**
 * 路径  end
 * ----------------------------------------------------------------------------------------------------------------------
 */

// 根据ID，获取详情
export const getMarkCargo = id => {
  return axios.get(MARKCARGO_BY_ID + id.join(','));
};

// 查询字典项
export const searchDictEntitys = id => {
  return axios.get(DICTENTITY, {params: {dictCode: id}});
};
// 获取短驳列表
export const searchMarkCargos = params => {
  return axios.get(MARKCARGOS, {params: params});
};

/**
 * 获取短驳列表--不分页
 *
 * @param params
 * @returns {AxiosPromise}
 */
export const searchMarkCargoNoPage = params => {
  return axios.get(MARK_CARGO_NO_PAGE, {params: params});
};

// 批量启用/停用
export const batchStart = (id, isStart) => {
  return axios.post(MARKCARGO, qs.stringify({id: id.join(','), isStart: isStart}));
};

// 批量删除短驳
export const batchDel = id => {
  return axios.delete(MARKCARGOS_DEL + id.join(','));
};

// 根据ID，获取地址列表
export const getAddresses = id => {
  let myid = `pid=` + id;
  return axios.get(ADDRESS_DICTS, {params: {filters: myid}});
};

// 获取机构列表
export const searchOrganization = params => {
  return axios.get(ORGANIZATION_LIST, {params: params});
};

// 保存/修改短驳
export const saveMarkCargo = (params) => {
  return axios.post(MARKCARGOS, params);
};

// 保存/修改短驳地址
export const saveMarkCargoAddress = (params) => {
  return axios.post(MARK_CARGO_ADDRESSS, params);
};

// 根据userid且短驳ID为空获取短驳地址
export const getMarkCargoAddressByUserId = params => {
  return axios.get(MARK_CARGO_ADDRESS, {params: params});
};

// 根据userid获取短驳地址
export const getMarkCargoAddress = params => {
  return axios.get(MARK_CARGO_ADDRESS_BY_ID_IS_NULL, {params: params});
};

// 删除短驳地址
export const deleteMarkCargoAddress = markCargoId => {
  return axios.delete(MARK_CARGO_ADDRESS_BY_MARK_CARGO_ID + markCargoId);
};

// 根据短驳ID获取短驳地址
export const getMarkCargoAddresss = markCargoId => {
  return axios.get(MARK_CARGO_ADDRESS_BY_MARK_CARGO_ID + markCargoId);
};

// 删除短驳地址根据USERID和短驳ID为空
export const deleteMarkCargoAddressByUseridAndMarkCargoId = id => {
  return axios.delete(MARK_CARGO_ADDRESS_DEL_BY_USER_ID_MARK_CARGO_ID + id);
};
// 根据userid and markcargoid查找短驳地址列表
export const findByUserIdAndMarkCargoId = params => {
  return axios.get(MARK_CARGO_ADDRESS__BY_USER_ID_MARK_CARGO_ID, {params: params});
};
